package cn.whale.kill.web.controller;

import cn.whale.kill.service.IKillSessionsService;
import cn.whale.kill.domain.KillSessions;
import cn.whale.kill.query.KillSessionsQuery;
import cn.whale.basic.utils.JSONResult;
import cn.whale.basic.utils.PageList;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/killSessions")
public class KillSessionsController {
    @Autowired
    public IKillSessionsService killSessionsService;


    /**
     * 查看所有的员工信息
     * @return
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JSONResult list(){
        return JSONResult.success(killSessionsService.selectKillSessions());
    }

    /**
    * 保存和修改公用的
    * @param killSessions  传递的实体
    * @return Ajaxresult转换结果
    */
    @RequestMapping(value="/save",method= RequestMethod.POST)
    public JSONResult save(@RequestBody KillSessions killSessions){
        if(killSessions.getId()!=null){
            killSessionsService.updateById(killSessions);
        }else{
            killSessionsService.insert(killSessions);
        }
        return JSONResult.success();
    }

    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @RequestMapping(value="/{id}",method=RequestMethod.DELETE)
    public JSONResult delete(@PathVariable("id") Long id){
        killSessionsService.deleteById(id);
        return JSONResult.success();
    }

    //获取用户
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JSONResult get(@PathVariable("id")Long id){
        return JSONResult.success(killSessionsService.selectById(id));
    }



    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @RequestMapping(value = "/pagelist",method = RequestMethod.POST)
    public JSONResult json(@RequestBody KillSessionsQuery query)
    {
        Page<KillSessions> page = new Page<KillSessions>(query.getPage(),query.getRows());
        page = killSessionsService.selectPage(page);
        return JSONResult.success(new PageList<KillSessions>(page.getTotal(),page.getRecords()));
    }
}
